﻿using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Omu.Awesome.Mvc.Helpers
{
    public static class AjaxCheckBoxListHelpers
    {
        public static MvcHtmlString AjaxCheckBoxList(this HtmlHelper html, AjaxCheckBoxListParams o)
        {
            o.ReadMeta(html);
            o.Value = o.Value.FromModel(html, o.Prop);

            var hd = o.HtmlAttributes.GetDictionary();

            var h = !html.ViewData.ModelState.IsValidField(o.Prop)
                        ? hd.AddVal("class", "input-validation-error")
                        : hd;

            o.Controller = o.Controller.DefaultController(o.Prop, "AjaxCheckBoxList");
            var info = new AjaxCheckBoxListInfo { HtmlAttributes = h.ToHtml() };
            info.ReadParams(o);

            return html.Partial(Settings.AwesomeFolder + "AjaxCheckBoxList.ascx", info);
        }

        public static MvcHtmlString AjaxCheckBoxList(this HtmlHelper html,
                                                     string prop,
                                                     object value = null,
                                                     string controller = null,
                                                     object htmlAttributes = null,
                                                     string prefix = null,
                                                     string parentId = null,
                                                     string area = null)
        {
            return
                html.AjaxCheckBoxList(new AjaxCheckBoxListParams
                                          {
                                              Controller = controller,
                                              HtmlAttributes = htmlAttributes,
                                              ParentId = parentId,
                                              Prefix = prefix,
                                              Prop = prop,
                                              Value = value,
                                              Area = area
                                          });
        }
    }
}